package com.game.majiang.vo;

import java.sql.SQLException;
import java.sql.Types;

import javax.sql.rowset.CachedRowSet;

import com.game.server.db.Parameter;
import com.game.server.db.ParameterType;
import com.game.server.db.SqlHelper;
import com.game.server.db.SqlHelperwrite;

import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class ClubapplyVo {
	
	int clubid;
	String clubname;
	int applyid;
	int status;
	
	public  void  insertClubapply() {
		String cmdText = "insert into clubapply(clubid,clubname,applyid,status,createtime)values(?,?,?,?,now())";
		Parameter p1 = new Parameter(Types.INTEGER, clubid, ParameterType.Input);
		Parameter p2 = new Parameter(Types.VARCHAR, clubname, ParameterType.Input);
		Parameter p3 = new Parameter(Types.INTEGER, applyid, ParameterType.Input);
		Parameter p4 = new Parameter(Types.INTEGER, status, ParameterType.Input);
		SqlHelperwrite.execute(cmdText,p1,p2,p3,p4);
	}
	
	public int checkapply() {
		String cmdText = "select id from clubapply where clubid=? and status =0 ";
		Parameter p1 = new Parameter(Types.INTEGER, clubid, ParameterType.Input);
		Object obj=SqlHelper.execScalar(cmdText,p1);
		if(obj!=null){
			return (int)obj;
		}else{
			return 0;
		}
	} 
	
	public static int selectapplyclub(int id) {
		int clubid=0;
		String cmdText = "select clubid from clubapply where id =? ";
		Parameter p1 = new Parameter(Types.INTEGER, id, ParameterType.Input);
		CachedRowSet rs = SqlHelper.getResultSet(cmdText,p1);
		try {
			if (rs.next()) 
			{  
				clubid=rs.getInt(1);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return clubid;
	} 

	public static void updateapplystatus(int id,int status) 
	{
		String cmdText = "UPDATE clubapply set status=? WHERE id=?";
		Parameter p1 = new Parameter(Types.INTEGER,status, ParameterType.Input);
		Parameter p2 = new Parameter(Types.INTEGER,id, ParameterType.Input);
		SqlHelperwrite.execute(cmdText, p1,p2);
	}
}
